import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/material.dart';
import 'package:flutter_deer/account/iview/withdraw_password_iview.dart';
import 'package:flutter_deer/account/models/withdraw_password_entity.dart';
import 'package:flutter_deer/mvp/base_page_presenter.dart';
import 'package:flutter_deer/net/base_entity.dart';
import 'package:flutter_deer/net/dio_utils.dart';
import 'package:flutter_deer/net/http_api.dart';
import 'package:flutter_deer/res/constant.dart';


class WithdrawPasswordPagePresenter extends BasePagePresenter<WithdrawPasswordIMvpView> {

  @override
  void initState() {
  }

  Future<dynamic> updateWithdrawPassowrd(String password) async {
    WithdrawPasswordEntity withdrawPasswordEntity = WithdrawPasswordEntity(withdrawPassword:password);
    WidgetsBinding.instance.addPostFrameCallback((_) {
      requestNetwork<OperatorBaseEntity>(Method.put,
          url: HttpApi.withdrawPasswordUpdate,
          params: withdrawPasswordEntity.toJson(),
          onSuccess: (data) {
            if(data!.data==true){
              SpUtil.putBool(Constant.existWithdralPassword, true);
              view.passwordChangeSuccess();
            }else{
              view.passwordChangeFail();
            }
          },
        onError: (error,msg){

        }
      );
    });
  }

  Future<dynamic> sendWithdrawPasswordSmsCode() async {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      requestNetwork<OperatorBaseEntity>(Method.get,
          url: HttpApi.withdrawPasswordSmsCode,
          onSuccess: (data) {
            if(data!.data==true){
              view.passwordChangeSuccess();
            }else{
              view.passwordChangeFail();
            }
          },
          onError: (error,msg){

          }
      );
    });
  }
}